﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UniMana.Utils.Controls;
namespace UniMana.Data
{
    public class Training_ScoreTypeInfo
    {
             #region /*Không thay đổi*/
            public bds m_bds = new bds();
            public void Save()
            {
                m_data.m_DCSave.SubmitChanges();
            }
            public void Delete()
            {
                m_bds.DeleteCurrent();
            }
            #endregion /*Không thay đổi*/
            private DBMain m_data = new DBMain();
            #region [Properties - Thuộc tính]
            public Training_ScoreType Properties
            {
                get { return m_bds.Current as Training_ScoreType; }
            }
            #endregion
            public Training_ScoreTypeInfo(int scoreTypeKey = 0)
            {
                var IQuery = m_data.m_DCSave.Training_ScoreTypes.Where(tb => tb.Training_ScoreTypeKey == scoreTypeKey);
                m_bds.DataSource = IQuery;
                var Row = IQuery.FirstOrDefault();
                if (Row == null)
                {
                    Row = new Training_ScoreType();
                    m_bds.Add(Row);
                }
            }
            /// <summary>
            /// Lấy danh sách loại điểm
            /// </summary>
            /// <param name="scoreTypeKey">Mã loại điểm</param>
            /// <returns></returns>
            public string getScoreTypeByKey(int scoreTypeKey)
            {
                string name = "";
                var s = from stn in m_data.m_DCReadOnly.Training_ScoreTypes
                        where stn.Training_ScoreTypeKey == scoreTypeKey
                        select stn;
                foreach (var i in s)
                {
                    name = i.Name.ToString();
                }
                return name;
            }
    }
}
